package com.cskaoyan.user.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.user.constants.UserRetCode;
import com.cskaoyan.user.dto.UserRegisterRequest;
import com.cskaoyan.user.dto.UserRegisterResponse;
import com.cskaoyan.user.service.UserRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


/**
 * @author sosog
 * @version 1.0.0
 * @description TODO
 * @date 2022/6/17 21:14
 */
@RestController
@RequestMapping("/user")
public class UserRegisterController {

    @Autowired
    UserRegisterService registerService;


    @PostMapping("/register")
    public ResponseData register(@RequestBody UserRegisterRequest request, HttpServletRequest servletRequest) {
        UserRegisterResponse response = registerService.register(request,servletRequest);
        if (response.getCode().equals(UserRetCode.SUCCESS.getCode())) {
            return new ResponseUtil<>().setData(null);
        }
        return new ResponseUtil<>().setErrorMsg(response.getMsg());
    }
}
